/**
 * File with initialisation of jQuery
 * 
 * @author Erwin Goossen
*/
var configFile 	= new createConfig(1,'CollectionDump.sql');
var curRelease 	= new currentRelease('');
var lyrics 		= [];
var getUrl 		= '';
var release 	= '';
var image 		= '';
var connUrl 	= null;
var bConnection = false;

$(document).ready(
function(){
	setupDb();
	setConfig();
	checkConnection();
	
//*** Global & buttons ***//	
	$('#combo').change(function(){
		showReleases($(this).val());
	});
	
	$('#tabs').tabs({
		fx: {
			opacity: 'toggle',
			duration: 'slow'
		}
	});
	
	$('#sql').click(
	function() {
		addArtist();
	});
	
	$('#quit').click(
	function() {
		window.close();
	});

	$('#info').click(
	function() {
		var message =  '<h2>AirCollection 0.1</h2>';
		message 	+= 'An easy to use Collection manager.';
		message		+= '<p>Created by: Erwin Goossen<br/><a href="http://navelpluisje.nl">Navelpluisje.nl</a>';
		showMessage("Info",message);
	});
	
	$('#info').click(function(){getLyric('prince', 'purple rain')});
	
//***  Tooltip Actions ***//
	$('.tooltip').mouseover(
	function (e) {
		showTooltip($(this).attr('title'),e);
	});
	
	$('.tooltip').mouseout(
	function () {
		hideTooltip();
	});
	
//*** Configuration Window  ***//	
	$('#saveConfig').click(
	function() {
		configFile.saveConfig();
		writeFile('config.xml',configFile.getXML());
		showMessage("Info", 'Wijzigingen opgeslagen.');
	});
	
	$('#getLocation').click(
	function() {
		getLocation();
		configFile.showConfig();
	});
	
//*** Retrieving Releaseinfo ***//
	$('.menuSearch').click(
	function() {
		$('#inpArtist').focus();
	});
	
	$('#inpArtist').keydown(
	function(e){
		if (e.keyCode == '13') {
		getData();
		}
	});

	$('#inpAlbum').keydown(
	function(e){
		if (e.keyCode == '13') {
		getData();
		}
	});

	$('#data').click(
	function(){
		getData();
	});
	
//*** CoverImage actions incl. Drag & Drop ***//	
	$('#busy').ajaxStart(
	function() {
  		$(this).css('visibility', 'visible');
	});
	$('#busy').ajaxStop(
	function() {
  		$(this).css('visibility', 'hidden');
	});
	
	$('#cover').draggable({
		opacity: 0.5,
		helper: "clone",
		drag: function(e,ui) {
			$('#dropbox').removeClass('shade');
			$('#dropbox').addClass('drophover');
			$(this).addClass('shade');
		},
		stop: function(e,ui) {
			$('#dropbox').addClass('shade');
			$('#dropbox').removeClass('drophover');
			$(this).removeClass('shade');
		}
	});
	
	$('#dropbox').droppable({
		drop: function(e, ui) {
			addRelease();
			showMessage('Toegevoegd','<br/><br/>Album toegevoegd');
			showReleases($('#combo').val());
			$(this).addClass('shade');
		}
	});

//*** Open all urls in external browser ***//
	$('a[href^=http]').live("click", function(e){
  		e.preventDefault();
  		openExternalURL(this.href);
 	});
	
	$('#alertMessage').dialog({
		autoOpen: false,
		show: 'slide',
		buttons: {
			Ok: function() {
				$(this).dialog('close');
//				$('#alertMessage').unbind('dialog');
//				$('#alertMessage').css('visibility','hidden');
			}
		},
		modal: true
	});


	fillReleaseCombo();
	showReleases(''); // show all releases by default
});

